***************************************
** Title	: 	Paper datawork (Main Results in Paper)		
** Data		:	NIDS				
** Author	: 	Mo Alloush			
** Date		:	January, 2023			
***************************************
clear all
set more off
set maxvar 20000

/*put NIDS_1_2_3_4_5.dta and datasetup_EDCC_final in folder
*/

cd "$folder"

quietly do datasetup_EDCC_final


*1.Table 1: Summary Stats

egen scalemiss = count(w_scale), by(pid)
sum w_hhincome_per w_expf_per w_totindinc w_scale w_hhsizer male w_age [aw=w_pweight] if wave==4 & scalemiss==4 

*2.Full Sample System Regressions - Table 2

eststo: gmm 	(eq1: d.w_totindinc - {xb: d.w_scale d.l.w_totindinc }) ///
		(eq2: d.w_scale - {xc: d.w_hhincome_per d.l.w_scale }) ///
, ///
instruments(eq1: l2.w_scale l3.w_scale l3.w_totindinc )  ///
instruments(eq2: l3.w_scale l2.w_scale l3.w_hhincome_per l2.w_hhincome_per) ///
winitial(unadjusted, independent) wmatrix(cluster cluster) twostep

eststo: gmm 	(eq1: d.w_totindinc - {xb: d.w_scale d.l.w_totindinc }) ///
		(eq2: d.w_scale - {xc: d.w_hhincome_per d.w_hhincome_per_sq d.l.w_scale }) ///
, ///
instruments(eq1: l2.w_scale l3.w_scale l3.w_totindinc )  ///
instruments(eq2: l3.w_scale l2.w_scale l3.w_hhincome_per l3.w_hhincome_per_sq l2.w_hhincome_per l2.w_hhincome_per_sq ) ///
winitial(unadjusted, independent) wmatrix(cluster cluster) twostep

eststo: gmm 	(eq1: d.w_totindinc - {xb: d.w_scale d.l.w_totindinc d.w_married d.w_hhsizer d.w_children d.w_disability}) ///
		(eq2: d.w_scale - {xc: d.w_hhincome_per d.w_hhincome_per_sq d.l.w_scale d.w_married d.w_hhsizer d.w_children d.w_disability}) ///
, ///
instruments(eq1: l2.w_scale l3.w_scale l3.w_totindinc d.w_married d.w_hhsizer d.w_children d.w_disability)  ///
instruments(eq2: l3.w_scale l3.w_hhincome_per l3.w_hhincome_per_sq l2.w_hhincome_per l2.w_hhincome_per_sq d.w_married d.w_hhsizer d.w_children d.w_disability) ///
winitial(unadjusted, independent) wmatrix(cluster cluster) twostep

eststo: gmm 	(eq1: d.w_totindinc - {xb: d.w_scale d.l.w_totindinc d.w_married d.w_hhsizer d.w_children d.w_disability}) ///
		(eq2: d.w_scale - {xc: d.w_hhincome_per d.w_hhincome_per_sq d.l.w_scale d.w_married d.w_hhsizer d.w_children d.w_disability}) ///
, ///
instruments(eq1: l3.w_scale l3.w_totindinc l3.w_hhincome_per d.w_married d.w_hhsizer d.w_children d.w_disability)  ///
instruments(eq2: l3.w_scale l3.w_hhincome_per l3.w_hhincome_per_sq l3.w_totindinc l3.w_totindinc_sq d.w_married d.w_hhsizer d.w_children d.w_disability) ///
winitial(unadjusted, independent) wmatrix(cluster cluster) twostep

*Table 3--Mechanisms

eststo: gmm 	(eq1: d.w_active - {xb: d.w_scale d.w_married d.w_hhsizer d.w_children d.w_disability}) ///
		(eq2: d.w_scale - {xc: d.w_hhincome_per d.w_hhincome_per_sq d.l.w_scale d.w_married d.w_hhsizer d.w_children d.w_disability}) ///
if w_age<60, ///
instruments(eq1: l2.w_scale l3.w_scale d.w_married d.w_hhsizer d.w_children d.w_disability)  ///
instruments(eq2: l3.w_scale l3.w_hhincome_per l3.w_hhincome_per_sq l2.w_hhincome_per l2.w_hhincome_per_sq d.w_married d.w_hhsizer d.w_children d.w_disability) ///
winitial(unadjusted, independent) wmatrix(cluster cluster) twostep

eststo: gmm 	(eq1: d.w_employed - {xb: d.w_scale d.w_married d.w_hhsizer d.w_children d.w_disability}) ///
		(eq2: d.w_scale - {xc: d.w_hhincome_per d.w_hhincome_per_sq d.l.w_scale d.w_married d.w_hhsizer d.w_children d.w_disability}) ///
if w_age<60 & w_active==1 & l.w_active==1, ///
instruments(eq1: l2.w_scale l3.w_scale d.w_married d.w_hhsizer d.w_children d.w_disability)  ///
instruments(eq2: l3.w_scale l3.w_hhincome_per l3.w_hhincome_per_sq l2.w_hhincome_per l2.w_hhincome_per_sq d.w_married d.w_hhsizer d.w_children d.w_disability) ///
winitial(unadjusted, independent) wmatrix(cluster cluster) twostep

eststo: gmm 	(eq1: d.w_hours - {xb: d.w_scale d.w_married d.w_hhsizer d.w_children d.w_disability}) ///
		(eq2: d.w_scale - {xc: d.w_hhincome_per d.w_hhincome_per_sq d.l.w_scale d.w_married d.w_hhsizer d.w_children d.w_disability}) ///
if w_age<60 & w_employed==1 & l.w_employed==1, ///
instruments(eq1: l2.w_scale l3.w_scale d.w_married d.w_hhsizer d.w_children d.w_disability)  ///
instruments(eq2: l3.w_scale l3.w_hhincome_per l3.w_hhincome_per_sq l2.w_hhincome_per l2.w_hhincome_per_sq d.w_married d.w_hhsizer d.w_children d.w_disability) ///
winitial(unadjusted, independent) wmatrix(cluster cluster) twostep

*Table 4--Other measures
eststo: gmm 	(eq1: d.w_totindinc - {xb: d.w_scale d.l.w_totindinc d.w_married d.w_hhsizer d.w_children d.w_disability}) ///
		(eq2: d.w_scale - {xc: d.w_expf_per d.w_expf_per_sq d.l.w_scale d.w_married d.w_hhsizer d.w_children d.w_disability}) ///
, ///
instruments(eq1: l2.w_scale l3.w_scale l3.w_totindinc d.w_married d.w_hhsizer d.w_children d.w_disability)  ///
instruments(eq2: l3.w_scale l2.w_expf_per l2.w_expf_per_sq l3.w_expf_per l3.w_expf_per_sq l3.w_hhincome_per l3.w_hhincome_per_sq l2.w_hhincome_per l2.w_hhincome_per_sq d.w_married d.w_hhsizer d.w_children d.w_disability) ///
winitial(unadjusted, independent) wmatrix(cluster cluster) twostep

eststo: gmm 	(eq1: d.w_totindinc - {xb: d.w_scale d.l.w_totindinc d.w_married d.w_hhsizer d.w_children d.w_disability}) ///
		(eq2: d.w_scale - {xc: d.w_wealthindex d.l.w_scale d.w_married d.w_hhsizer d.w_children d.w_disability}) ///
, ///
instruments(eq1: l3.w_scale l2.w_scale l3.w_totindinc d.w_married d.w_hhsizer d.w_children d.w_disability)  ///
instruments(eq2: l3.w_scale l2.w_wealthindex l2.w_hhincome_per l2.w_expf_per l3.w_wealthindex l3.w_hhincome_per l3.w_expf_per d.w_married d.w_hhsizer d.w_children d.w_disability) ///
winitial(unadjusted, independent) wmatrix(cluster cluster) twostep

*Assumptions B
eststo: gmm 	(eq1: d.w_totindinc - {xb: d.w_scale d.l.w_totindinc d.w_married d.w_hhsizer d.w_children d.w_disability}) ///
		(eq2: d.w_scale - {xc: d.w_expf_per d.w_expf_per_sq d.l.w_scale d.w_married d.w_hhsizer d.w_children d.w_disability}) ///
, ///
instruments(eq1: l3.w_scale l3.w_totindinc d.w_married d.w_hhsizer d.w_children d.w_disability)  ///
instruments(eq2: l3.w_scale l3.w_expf_per l3.w_expf_per_sq l3.w_hhincome_per l3.w_hhincome_per_sq d.w_married d.w_hhsizer d.w_children d.w_disability) ///
winitial(unadjusted, independent) wmatrix(cluster cluster) twostep

eststo: gmm 	(eq1: d.w_totindinc - {xb: d.w_scale d.l.w_totindinc d.w_married d.w_hhsizer d.w_children d.w_disability}) ///
		(eq2: d.w_scale - {xc: d.w_wealthindex d.l.w_scale d.w_married d.w_hhsizer d.w_children d.w_disability}) ///
, ///
instruments(eq1: l3.w_scale l3.w_totindinc d.w_married d.w_hhsizer d.w_children d.w_disability)  ///
instruments(eq2: l3.w_scale l3.w_wealthindex l3.w_expf_per l3.w_hhincome_per d.w_married d.w_hhsizer d.w_children d.w_disability) ///
winitial(unadjusted, independent) wmatrix(cluster cluster) twostep

